package me.joshua.demo4j.bae.tool4j.service;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.baidu.bae.api.bcms.BaeBcms;
import com.baidu.bae.api.bcms.model.concrete.MailRequest;
import com.baidu.bae.api.factory.BaeFactory;

@Service
public class EmailNotificationService {

	@Value("${notification.email.personalEmail}")
	private String personalEmail;
	@Value("${notification.email.bcmsQueueName}")
	private String bcmsQueueName;

	public void notifyByEmail(String subject, String message) {
		BaeBcms bcms = BaeFactory.getBaeBcms();
		MailRequest mailRequest = createMailRequest();
		mailRequest.setSubject(subject);
		mailRequest.setMessage(message);
		bcms.mail(mailRequest);
	}

	private MailRequest createMailRequest() {
		MailRequest mailRequest = new MailRequest();

		mailRequest.setQueueName(bcmsQueueName);
		mailRequest.addMailAddress(personalEmail);
		mailRequest.setFrom(personalEmail);

		return mailRequest;
	}
}
